package com.spx.core.wizards;

import org.apache.commons.lang.StringUtils;
import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import com.spx.core.types.User;

/**
 * The "New" wizard page allows setting the container for the new file as well
 * as the file name. The page will only accept file name without the extension
 * OR with the extension that matches the expected one (mpe).
 */

public class NewUserContactPage extends ModelWizardPage<User>
{

	private Text emailText;

	/**
	 * Constructor for SampleNewWizardPage.
	 * 
	 * @param pageName
	 */
	public NewUserContactPage()
	{
		super("wizardPage");
		setTitle("New User Contact Details");
		setDescription("Contact information.");

	}

	/**
	 * @see IDialogPage#createControl(Composite)
	 */
	public void createControl(Composite parent)
	{
		final Composite container = new Composite(parent, SWT.NULL);
		final GridLayout layout = new GridLayout();
		container.setLayout(layout);
		layout.numColumns = 2;
		layout.verticalSpacing = 9;
		final Label label = new Label(container, SWT.NULL);
		label.setText("&Email:");

		emailText = new Text(container, SWT.BORDER | SWT.SINGLE);
		final GridData gd = new GridData(GridData.FILL_HORIZONTAL);
		emailText.setLayoutData(gd);
		emailText.addModifyListener(new ModifyListener()
		{
			public void modifyText(ModifyEvent e)
			{
				dialogChanged();
			}
		});

		initialize();
		dialogChanged();
		setControl(container);
	}

	/**
	 * Tests if the current workbench selection is a suitable container to use.
	 */

	private void initialize()
	{

	}

	/**
	 * Ensures that both text fields are set.
	 */

	private void dialogChanged()
	{

		if (StringUtils.isBlank(this.emailText.getText()))
		{
			updateStatus("email must be specified");
		} else
		{
			updateStatus(null);
		}

	}

	private void updateStatus(String message)
	{
		setErrorMessage(message);
		setPageComplete(message == null);
	}

	@Override
	public void setProperties(User modelObject)
	{
		modelObject.setEmailAddress(emailText.getText());

	}

	@Override
	protected void createPageControl(Composite parent)
	{
		// TODO Auto-generated method stub

	}

}